﻿namespace AC.ExtendedRenderer.Toolkit.Utils
{
    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Text;

    internal class Win32
    {
        public const int GW_CHILD = 5;
        public const int GW_HWNDFIRST = 0;
        public const int GW_HWNDLAST = 1;
        public const int GW_HWNDNEXT = 2;
        public const int GW_HWNDPREV = 3;
        public const int GW_OWNER = 4;
        public const int GWL_WNDPROC = -4;
        public const int HC_ACTION = 0;
        public const int WH_CALLWNDPROC = 4;
        public const int WM_CREATE = 1;
        public const int WM_DESTROY = 2;
        public const int WM_ERASEBKGND = 20;
        public const int WM_HSCROLL = 0x114;
        public const int WM_NCCALCSIZE = 0x83;
        public const int WM_NCCREATE = 0x81;
        public const int WM_NCHITTEST = 0x84;
        public const int WM_NCPAINT = 0x85;
        public const int WM_PAINT = 15;
        public const int WM_PARENTNOTIFY = 0x210;
        public const int WM_PRINT = 0x317;
        public const int WM_SHARED_MENU = 0x1e2;
        public const int WM_SHOWWINDOW = 0x18;
        public const int WM_WINDOWPOSCHANGING = 70;

        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
        [DllImport("Gdi32.dll", CharSet=CharSet.Auto)]
        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern int GetClassName(IntPtr hwnd, char[] className, int maxCount);
        [DllImport("user32", CharSet=CharSet.Auto)]
        public static extern int GetClientRect(IntPtr hwnd, ref RECT lpRect);
        [DllImport("user32", CharSet=CharSet.Auto)]
        public static extern int GetClientRect(IntPtr hwnd, [In, Out] ref Rectangle rect);
        [DllImport("user32.dll")]
        public static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgnclip, uint fdwOptions);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern IntPtr GetWindow(IntPtr hwnd, int uCmd);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern IntPtr GetWindowDC(IntPtr handle);
        [DllImport("user32.dll", CharSet=CharSet.Auto)]
        internal static extern bool GetWindowRect(IntPtr hWnd, [In, Out] ref Rectangle rect);
        [DllImport("user32", CharSet=CharSet.Auto)]
        public static extern bool InvalidateRect(IntPtr hwnd, ref Rectangle rect, bool bErase);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern bool IsWindowVisible(IntPtr hwnd);
        [DllImport("user32", CharSet=CharSet.Auto)]
        public static extern bool MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
        [DllImport("User32", CallingConvention=CallingConvention.Cdecl)]
        public static extern int RealGetWindowClass(IntPtr hwnd, StringBuilder pszType, int cchType);
        [DllImport("user32.dll")]
        public static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC);
        [DllImport("user32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        public static extern IntPtr SetClipboardViewer(IntPtr hWnd);
        [DllImport("user32")]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        [DllImport("uxtheme.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
        public static extern int SetWindowTheme(IntPtr hWnd, int pszSubAppName, int pszSubIdList);
        [DllImport("uxtheme.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
        public static extern int SetWindowTheme(IntPtr hWnd, int pszSubAppName, string pszSubIdList);
        [DllImport("uxtheme.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
        public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, int pszSubIdList);
        [DllImport("uxtheme.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
        public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
        [DllImport("user32", CharSet=CharSet.Auto)]
        public static extern bool UpdateWindow(IntPtr hwnd);
        [DllImport("user32", CharSet=CharSet.Auto)]
        public static extern bool ValidateRect(IntPtr hwnd, ref Rectangle rect);

        [StructLayout(LayoutKind.Sequential)]
        public struct NCCALCSIZE_PARAMS
        {
            public Win32.RECT rgc;
            public Win32.WINDOWPOS wndpos;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct WINDOWPOS
        {
            public IntPtr hwnd;
            public IntPtr hwndAfter;
            public int x;
            public int y;
            public int cx;
            public int cy;
            public uint flags;
        }
    }
}

